\font\sectionfont=cmbx10 scaled\magstep2
\font\subsectionfont=cmbx10 scaled\magstep1
\font\subsubsectionfont=cmbx10 scaled\magstephalf

\def\<{$\langle$}
\def\>{$\rangle$}

\parskip=3mm
\parindent=0mm

\def\tab#1{ \medskip \leftskip=1cm
{\openup2pt\halign{
##\hfil & ##\hfil & ##\hfil\cr
#1 }} \leftskip=0cm}

\def\itm#1{\hangindent\itmindent
	\setbox0=\hbox{#1\quad}%
	\ifdim\wd0<\itmindent \dimen0=\itmindent\advance\dimen0 -\wd0
	\else \dimen0=0pt\fi
	\unhbox0\hskip\dimen0}

\newdimen\itmindent \itmindent=2em

\def\section#1\par{%
	\vskip0pt plus .35\vsize\penalty-350%
	\vskip0pt plus-.35\vsize\vskip16pt plus5pt minus5pt\vskip\parskip
	\message{#1}%
	\noindent{\sectionfont\ignorespaces#1}\par\nobreak
	\write\mycontentsout{\medskip
	   {\bf\ignorespaces#1\hfill\folio\noexpand\par}}%
	\vskip10pt plus4pt minus4pt\noindent}

\def\subsection#1\par{%
	\vskip0pt plus .25\vsize\penalty-250%
	\vskip0pt plus-.25\vsize\vskip9pt plus3pt minus3pt\vskip\parskip
	\noindent{\subsectionfont\ignorespaces#1}\par\nobreak
	\write\mycontentsout{%
	   {\rm\qquad\ignorespaces#1\mycontentsleaders\folio\noexpand\par}}%
	\vskip6pt plus2pt minus2pt\noindent}

\def\subsubsection#1\par{%
	\vskip0pt plus .2\vsize\penalty-200%
	\vskip0pt plus-.2\vsize\vskip5pt plus2pt minus2pt\vskip\parskip
	\noindent{\subsubsectionfont\ignorespaces#1}\par\nobreak
	\write\mycontentsout{%
	   {\rm\qquad\ignorespaces#1\mycontentsleaders\folio\noexpand\par}}%
	\vskip4pt plus1pt minus1pt\noindent}

\def\mycontentsleaders{{\rm\leaders\hbox to2em{\hss.\hss}\hfill}}

\newwrite\mycontentsout
\openout\mycontentsout=\jobname.cont

\def\contents{%
	\vfill\break
	\mycontentspageno=\pageno
	\pageno=\contentspageno
	\message{Contents}
	\noindent{\sectionfont Contents}\par\nobreak
	\vskip10pt plus4pt minus4pt\noindent
	\immediate\closeout\mycontentsout
	\openin\mycontentsin=\jobname.cont
	\begingroup
	  \parindent=0pt\parskip=3pt
	  \catcode`@=11
	  \def\myreadcontentsline{\ifeof\mycontentsin%
	  \let\myreadcontentsline=\empty
	  \else\read\mycontentsin to\mycontentsline\mycontentsline\fi
	  \myreadcontentsline}%
	  \myreadcontentsline
	\endgroup
	\closein\mycontentsin
	\openout\mycontentsout=jobname.cont
	\vfill\break
	\pageno=\mycontentspageno \advancepageno}

\newcount\contentspageno \contentspageno=-1
\newcount\mycontentspageno
\newread\mycontentsin
